package cn.qzzg.service.impl;

import cn.qzzg.common.exceptlion.CommonException;
import cn.qzzg.enums.CodeEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.qzzg.pojo.PotTime;
import cn.qzzg.service.PotTimeService;
import cn.qzzg.mapper.PotTimeMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 九九
 * @description 针对表【pot_time(锅次表)】的数据库操作Service实现
 * @createDate 2023-03-25 21:51:39
 */
@Service
public class PotTimeServiceImpl extends ServiceImpl<PotTimeMapper, PotTime>
        implements PotTimeService {

    /**
     * 通用条件构造器
     */
    private LambdaQueryWrapper<PotTime> wrapper;


    /**
     * 查询所有数据
     *
     * @return 结果对象集合
     */
    @Override
    public List<PotTime> findAll(PotTime potTime) {
        wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ObjectUtils.isNotEmpty(potTime.getPotTimeId()), PotTime::getPotTimeId, potTime.getPotTimeId())
                .eq(ObjectUtils.isNotEmpty(potTime.getCreateTime()), PotTime::getCreateTime, potTime.getCreateTime())
                .orderByDesc(PotTime::getCreateTime);
        return list(wrapper);
    }

    /**
     * 查询锅次信息
     * @param potTimeId
     * @return
     */
    @Override
    public PotTime findPotTimeInfo(Integer potTimeId) {
        wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ObjectUtils.isNotEmpty(potTimeId), PotTime::getPotTimeId, potTimeId);
        return getOne(wrapper);
    }

    /**
     * 添加一条数据
     *
     * @param obj 需要添加的对象
     * @return 添加的对象ID
     */
    @Override
    public Integer saveOne(PotTime obj) {
        if (ObjectUtils.isEmpty(obj))
            throw new CommonException(CodeEnum.USER_ERROR_A0410);
        save(obj);
        return obj.getPotTimeId();
    }
}




